﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;

namespace TanmiaGrp.GeneralLedger.WinApp
{
    public class IsTransactionalConverter : MarkupExtension, IValueConverter
    {
        private static IsTransactionalConverter converter;

        public IsTransactionalConverter()
        {
        }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int val = System.Convert.ToInt32(value);
            if (val == 0)
                return false;
            else if (val == 1)
                return true;

            throw new InvalidOperationException();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool val = System.Convert.ToBoolean(value);
            if (val == true)
                return 1;
            else
                return 0;
        }

        #endregion

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (converter == null)
                converter = new IsTransactionalConverter();

            return converter;
        }
    }
}
